
/* ScrollViewExtensions.m:
 * You may freely copy, distribute, and reuse the code in this example.
 * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
 * fitness for any particular use.
 *
 * A generic scrollview driver object to display/print text 
 * Written by Jack Greenfield
 *
 */

#import	<objc/objc-runtime.h>
#import "ScrollViewExtensions.h"

@implementation ScrollView(ScrollViewExtensions)

- sprintf:(const char *)format, ...
{
 	id text;
   	int length;
    static char buffer[65536];
    va_list arguments;

	va_start(arguments, format);
	vsprintf(buffer, format, arguments);
	va_end(arguments);
    
	text = [self docView];
	length = [text textLength];
	[text setSel:length :length];
	[text replaceSel:buffer];
	[text scrollSelToVisible];
    return self;
}

- vsprintf:(const char *)format arguments:(va_list)arguments
{
  	id text;
   	int length;
    static char buffer[65536];

	vsprintf(buffer, format, arguments);
	text = [self docView];
	length = [text textLength];
	[text setSel:length :length];
	[text replaceSel:buffer];
	[text scrollSelToVisible];
    return self;
}

- clear:sender
{
  	id text;
    int length;

	text = [self docView];
	length = [text textLength];
	[text setSel:0 :length];
	[text replaceSel:""];
	[text scrollSelToVisible];
    return self;
}

- print:sender
{
	[[self docView] printPSCode:sender];
    return self;
}

- printFrom:sender
{
    return [self sprintf:"%s\n", [sender stringValue]];
}

@end
